$(function() {
    //初始化
    Begin();
})

////////////--------------表格-数据--------------------////////////
/*var tableFirstClick = 0;
 var tableTab = new Vue({
 el: "#tableTab",
 data: function() {
 return {
 activeName: 'first'
 }
 },
 methods: {
 handleClick: function(tab, event) {
 //tab点击是否加载
 if(tab.index == tableFirstClick) {
 return;
 } else {
 tableFirstClick = tab.index;
 }
 if(tab.index == 1) {
 var table = new VanyTable({
 el: "#tableSecond",
 url: "templates/authority/messageHistory/json/queryOrgUserList1.json",
 index: true, //选框
 selection: true, //编号
 pageSize: 10, //默认每页10条
 //					pageSizes: [10, 20], //下拉分页
 pages: true, //是否需要分页，与scrollPage最好二选一
 scrollPage: false, //是否滚动分页，与pages最好二选一
 keys: [{
 "key": "user",
 "name": "姓名"
 }, {
 "key": "dept",
 "name": "部门"
 }, {
 "key": "setTime",
 "name": "送达时间"
 }, {
 "key": "getTime",
 "name": "查阅时间",
 "template": "<div v-if=\"scope.row.getTime === null\">--</div><div v-else><span v-text='scope.row.getTime'></span></div>"
 }, {
 "key": "status",
 "name": "操作",
 "template": '<div style="color:#0a6dcd" @click="handleEdit(scope.$index, scope.row)" v-if=\'scope.row.status === "0"\'>提醒</div><div v-else style=\'color:#bebebe;\'>已提醒</div>'
 }],
 // right、topRight、bottomLeft
 btnPostion: "bottomLeft",
 btnNotes: "<span><label>*</label>为了减少给用户带来的骚扰，提醒功能24H内只能使用1次/人</span>",
 btns: [{
 authority: "base_user_add",
 name: "批量提醒",
 click: function() {
 console.log("批量提醒");
 }
 }]
 });
 table.on("rowClick", function(index, row, event, column) {
 if(column.type === "selection" || column.property === "status") {
 return;
 }
 console.log("有行sdfvsd被单击了");
 });
 table.on("selectionChange", function(selection) {
 console.log("有行被sdfs选中啦");
 });
 Update();
 Edit();
 Search();
 }
 if(tab.index == 2) {
 var table = new VanyTable({
 el: "#tableThird",
 url: "templates/authority/messageHistory/json/queryOrgUserList2.json",
 index: true, //选框
 selection: true, //编号
 pageSize: 10, //默认每页10条
 //					pageSizes: [10, 20], //下拉分页
 pages: true, //是否需要分页，与scrollPage最好二选一
 scrollPage: false, //是否滚动分页，与pages最好二选一
 keys: [{
 "key": "user",
 "name": "姓名"
 }, {
 "key": "dept",
 "name": "部门"
 }, {
 "key": "setTime",
 "name": "送达时间"
 }, {
 "key": "getTime",
 "name": "查阅时间",
 "template": "<div v-if=\"scope.row.getTime === null\">--</div><div v-else><span v-text='scope.row.getTime'></span></div>"
 }],
 // right、topRight、bottomLeft
 btnPostion: "bottomLeft",
 btnNotes: "",
 btns: []
 });
 Update();
 Search();
 table.on("rowClick", function(index, row, event, column) {
 if(column.type === "selection" || column.property === "status") {
 return;
 }
 console.log("111111被单击了");
 });
 table.on("selectionChange", function(selection) {
 console.log("222222222选中啦");
 });
 }
 }
 }
 })

 var table = new VanyTable({
 el: "#table",
 url: "templates/authority/messageHistory/json/queryOrgUserList.json",
 index: true, //选框
 selection: true, //编号
 pageSize: 10, //默认每页10条
 //	pageSizes: [10, 20, 30], //下拉分页
 pages: true, //是否需要分页，与scrollPage最好二选一
 scrollPage: false, //是否滚动分页，与pages最好二选一
 keys: [{
 "key": "user",
 "name": "姓名"
 }, {
 "key": "dept",
 "name": "部门"
 }, {
 "key": "setTime",
 "name": "送达时间"
 }, {
 "key": "getTime",
 "name": "查阅时间",
 "template": "<div v-if=\"scope.row.getTime === null\">--</div><div v-else><span v-text='scope.row.getTime'></span></div>"
 }, {
 "key": "status",
 "name": "操作",
 "template": '<div style="color:#0a6dcd" @click="handleEdit(scope.$index, scope.row)" v-if=\'scope.row.status === "0"\'>提醒</div><div v-else style=\'color:#bebebe;\'>提醒</div>'
 }],
 // right、topRight、bottomLeft
 btnPostion: "bottomLeft",
 btnNotes: "<span><label>*</label>为了减少给用户带来的骚扰，提醒功能24H内只能使用1次/人</span>",
 btns: [{
 authority: "base_user_add",
 name: "批量提醒",
 click: function() {
 console.log("批量提醒");
 }
 }]
 });
 table.on("rowClick", function(index, row, event, column) {
 if(column.type === "selection" || column.property === "status") {
 return;
 }
 console.log("有一行被单击了");
 });
 table.on("selectionChange", function(selection) {
 console.log("有一行被选中啦");
 });
 //消息提醒
 Update();
 Edit();
 Search();

 function Update() {
 table.getData({
 orgCode: "000000",
 searchValue: "",
 status: ""
 }, true);
 }

 function Edit() {
 table.on("handleEdit", function(index, row) {
 var self = this;
 this.$confirm("确认提醒\n" + row.dept + "/" + row.user + "？")
 .then(function() {
 row.status = "1";
 done();
 })
 .catch(function() {});
 VanyAjax.prototype.hideLoading()
 });
 };

 function Search() {
 table.on("search", function(val) {
 table.getData({
 orgCode: "000000",
 searchValue: val,
 status: ""
 }, true);
 });
 };
 */
////////////--------------统计图表--------------------////////////
var xAxisData = [],
    yAxisData = [],
    option,
    tabFirstClick;

//参数为当天24小时
$.ajax({
    type: "get",
    url: "templates/authority/messageHistory/json/data.json",
    async: true,
    success: function(data) {
        var echartFirst = echarts.init(document.getElementById('chartFirst'));
        for(var i = 0; i < data.resultData.rows.length; i++) {
            xAxisData.push(data.resultData.rows[i].setTime);
            yAxisData.push(data.resultData.rows[i].number);
        }
        EchartOption(echartFirst);
    }
});

var chartTab = new Vue({
    el: "#chartTab",
    data: function() {
        return {
            activeName: 'chartFirst'
        }
    },
    methods: {
        handleClick:function(tab, event) {
            //tab点击是否加载
            if(tab.index == tabFirstClick) {
                return;
            } else {
                xAxisData = [];
                yAxisData = [];
                tabFirstClick = tab.index;
            }
            if(tab.index == 1) {
                //参数为最新一周
                $.ajax({
                    type: "get",
                    url: "templates/authority/messageHistory/json/data.json",
                    async: true,
                    success: function(data) {
                        var echartSecond = echarts.init(document.getElementById('chartSecond'));
                        for(var i = 0; i < data.resultData.rows.length; i++) {
                            xAxisData.push(data.resultData.rows[i].setTime);
                            yAxisData.push(data.resultData.rows[i].number);
                        }
                        EchartOption(echartSecond);
                    }
                });
            }
            if(tab.index == 2) {
                //参数为最新一月
                $.ajax({
                    type: "get",
                    url: "templates/authority/messageHistory/json/data.json",
                    async: true,
                    success: function(data) {
                        var echartThird = echarts.init(document.getElementById('chartThird'));
                        for(var i = 0; i < data.resultData.rows.length; i++) {
                            xAxisData.push(data.resultData.rows[i].setTime);
                            yAxisData.push(data.resultData.rows[i].number);
                        }
                        EchartOption(echartThird);
                    }
                });
            }
        }
    }
})

function EchartOption(obj) {
    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'line',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        color: ['#c6f5e5'],
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            data: xAxisData
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
            name: '确认人数',
            type: 'line',
            areaStyle: {
                normal: {}
            },
            data: yAxisData
        }]
    };
    //每次窗口大小改变的时候都会触发onresize事件，这个时候我们将echarts对象的尺寸赋值给窗口的大小这个属性，从而实现图表对象与窗口对象的尺寸一致的情况
    window.onresize = obj.resize;
    obj.setOption(option);
}

//初始化
function Begin() {
    //面包屑
    new Vue().$mount('#crumbs');
    //获取整个菜单
    new Vue().$mount('#menuL');
    //左菜单滚动
    var oTop = $(".vany_authority").offset().top + 14;
    var sTop = 0;
    $(".vany_authority").scroll(function() {
        sTop = $(this).scrollTop();
        if(sTop >= oTop) {
            $("#menuL").css({
                "position": "fixed",
                "top": "60px"
            });
        } else {
            $("#menuL").css({
                "position": "absolute",
                "top": "0"
            });
        }
    });
    sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}
